package com.csx.base.design.behavior.chainOfResponsibility.example.exampleA.model.vo;

import lombok.Data;

/**
 * @author cuisongxu
 * @date 2022/12/28 22:24
 */
@Data
public class Result {

    public static final String SUCCESS_MESSAGE = "success";

    public static final String FAILURE_MESSAGE = "failed";

    public static final int SUCCESS_CODE = 200;

    public static final int FAILURE_CODE = 400;

    private String message;

    private int code;

    public static Result success() {
        Result result = new Result();
        result.setCode(Result.SUCCESS_CODE);
        result.setMessage(Result.SUCCESS_MESSAGE);
        return result;
    }

    public static Result failure() {
        Result result = new Result();
        result.setCode(Result.FAILURE_CODE);
        result.setMessage(Result.FAILURE_MESSAGE);
        return result;
    }

    public static Result failure(String msg) {
        Result result = new Result();
        result.setCode(Result.FAILURE_CODE);
        result.setMessage(msg);
        return result;
    }

    public boolean isSuccess() {
        return SUCCESS_CODE == this.code;
    }
}
